export const isLogin = () => {
	if (uni.getStorageSync('userInfo')) {
		return true
	}
	return false
}

export const getUid = () => {
	let uid = uni.getStorageSync('uid')
	if (uid) {
		return uid
	}
}

export const getUCode = () => {
	let ucode = uni.getStorageSync('code')
	if (ucode) {
		return ucode
	}
}

export const convertToTreeArray_ = (items) => { //树形数据处理
	const map = {};
	const result = [];
	items.forEach(item => {
		map[item.value] = {
			...item,
			children: []
		};
	});
	items.forEach(item => {
		if (item.parent !== null && map[item.parent]) {
			map[item.parent].children.push(map[item.value]);
		} else {
			result.push(map[item.value]);
		}
	});

	return result;
}

const addZero_ = (num) => {
    return num < 10 ? "0" + num : num;
}

export const timeFormat_ = (timestamp) => {  //时间格式化函数
    let date = new Date(0);
    date.setUTCSeconds(timestamp);
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let formattedDate = year + "-" + addZero_(month) + "-" + addZero_(day);
    return formattedDate;
}